#include<bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define mid ((l+r)>>1)
#define File(xxx) freopen(xxx".in","r",stdin),freopen(xxx".out","w",stdout)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);p3=obuf;}
}
using namespace IO;
const int N=1e6+5;
const ll Inf=1e18;
int n,m,len;
int a[N],c[N];
vector<int>w[N];
ll f[2][N],ans=Inf;
bool check(){
	for(int i=1;i<n;i++)
		if(a[i]>a[i+1])
			return 0;
	return 1; 
}
signed main(){
	File("minimize");
	read(n,m);
	for(int i=1;i<=n;i++)
		read(a[i]);
	if(check()){
		ll sum=0;
		for(int i=1;i<=n;i++){
			sum+=a[i];
			ans=min(ans,1ll*i*a[i]-sum+1ll*(n-i)*m);
		}
		write(ans);
		return flush(),0;
	}
	for(int i=1;i<=n;i++)
		c[i]=a[i];
	sort(c+1,c+n+1);
	len=unique(c+1,c+n+1)-c-1;
	for(int i=1;i<=n;i++){
		int j=lower_bound(c+1,c+len+1,a[i])-c;
		w[j].push_back(i);
	}
	memset(f,0x3f,sizeof f);
	f[0][n]=0;
	for(int i=1;i<=len;i++){
		for(int j=1;j<=n;j++)
			f[1][j]=Inf;
		ll sum=0;
		for(int j=1,k=0;j<=n;j++){
			if(a[j]<c[i])sum+=c[i]-c[i-1];
			f[1][j]=f[0][j]+sum;
		}
		for(int j=n-1;j>=1;j--)
			f[1][j]=min(f[1][j],f[1][j+1]+(a[j+1]>c[i])*m);
		ans=min(ans,f[1][1]+(a[1]>c[i])*m);
		swap(f[0],f[1]); 
	}
	write(ans);
	return flush(),0;
}
